<?php


namespace App\Http\Util;

use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\DB;

class SendSms
{
//企业ID $userid
    private $userid = '6540';
//用户账号 $account
    private $account = 'dn21';
//用户密码 $password
    private $password ='dn21963';
//发送到的目标手机号码 $mobile
    private $mobile;
//短信内容 $content
    private $content;
//验证码 $code
    private $code;
// send url
    private $gateway = "http://sh2.ipyy.com/sms.aspx?action=send";


    public function __construct(int $code, string $mobile){

        $this->mobile = $mobile;
        $this->code = $code;
        $this->content = urlencode("【简果】用户您好，您的验证码为：".$this->code."；如非本人操作，请忽略此信息。");
   }
    public function sendMsg(){
        $gateway = $this->gateway."&userid={$this->userid}&account={$this->account}&password=".md5($this->password)."&mobile={$this->mobile}&content={$this->content}&sendTime=";
        $result = file_get_contents($gateway);
        $xml = simplexml_load_string($result);
        return $xml->returnstatus;
//        echo "返回状态为：".$xml->returnstatus."<br>";
//        echo "返回信息：".$xml->message."<br>";
//        echo "返回余额：".$xml->remainpoint."<br>";
//        echo "返回本次任务ID：".$xml->taskID."<br>";
//        echo "返回成功短信数：".$xml->successCounts."<br>";
//        echo "<br>";
//        echo "<br>";
    }

}
